import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:sainbainu/common/routes/routes.dart';
import 'package:sainbainu/common/services/user.dart';
import 'package:sainbainu/common/values/sizes.dart';
import 'package:sainbainu/common/widgets/widget.dart';
import 'package:sainbainu/view/my/my_collect/index.dart';
import 'package:sainbainu/view/my/my_comment_forward/index.dart';
import 'package:sainbainu/view/my/my_like/view.dart';
import 'package:sainbainu/view/my/my_work/index.dart';
import 'package:sainbainu/view/my/widgets/widgets.dart';

import 'package:nested_scroll_view_plus/nested_scroll_view_plus.dart';

import 'index.dart';

class MyPage extends GetView<MyController> {
  const MyPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MyController>(
      builder: (_) {
        return Scaffold(
          body: LoginWrapper(child: _buildNestedScrollView()),
        );
      },
    );
  }

  /// 主视图
  Widget _buildNestedScrollView() {
    return NestedScrollViewPlus(
      controller: controller.state.scrollController,
      overscrollBehavior: OverscrollBehavior.outer,
      headerSliverBuilder: (context, innerScrolled) {
        return [
          CustomSliverAppBar(
            userInfo: UserService.to.accountInfo,
            headContent: HeadContent(
              accountInfo: UserService.to.accountInfo,
              onEditTap: () => Get.toNamed(AppRoutes.userInfo),
              onFansTap: () => Get.toNamed(AppRoutes.fans),
              onFollowTap: () => Get.toNamed(AppRoutes.follow),
            ),
            bottom: PreferredSize(
              preferredSize: Size(Get.width, kProfileTabbarHeight),
              child: const CustomTabBar(),
            ),
            onMore: () => Get.toNamed(AppRoutes.settings),
          ),
        ];
      },
      body: _buidBody(),
    );
  }

  /// 正文
  Widget _buidBody() {
    return TabBarView(
      controller: controller.state.tabController,
      children: [
        Container(
          key: const PageStorageKey<String>('work'),
          child: const MyWorkPage(),
        ),
        Container(
          key: const PageStorageKey<String>('like'),
          child: const MyLikePage(),
        ),
        Container(
          key: const PageStorageKey<String>('collect'),
          child: const MyCollectPage(),
        ),
        Container(
          key: const PageStorageKey<String>('commentForward'),
          child: const MyCommentForwardPage(),
        ),
      ],
    );
  }
}
